<!DOCTYPE html>
<html>

  <head>
    <meta charset="utf-8">
    <title>执行风险</title>
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <link href="../../../css/mui.min.css" rel="stylesheet" />
    <link href="../css/common.css" rel="stylesheet" />
    <link rel="stylesheet" type="text/css" href="../../../css/preview.css" />
    <style>
      .uls {
        padding: 20px 20px;
        list-style: none;
        margin: 0;
      }
      
      .mui-table-view:after {
        height: 0;
      }
      
      .titles {
        /* font-weight: bold; */
        margin-bottom: 24px;
      }
      
      .img_s {
        float: left;
        width: 20px;
        height: 20px;
        line-height: 20px;
        text-align: center;
        color: #fff;
        background-color: #0082E6;
        border-radius: 100%;
        /* background: url(../img/word.png) no-repeat; */
        /* background-size: 100%; */
        margin: auto 0;
      }
      
      .bocks {
        padding: 0 5px;
      }
      
      .areas {
        background-color: ##F5F6F7;
        border: solid 1px #DCDCDC;
      }
      
      .imgss {
        float: left;
        margin-right: 10px;
      }
      
      .imgss img {
        width: 100%;
      }
      
      .signs {
        display: inline-block;
        width: 160px;
        height: 160px;
        border: solid 1px #3188FE;
        border-radius: 5px;
        margin-right: 10px;
        margin-bottom: 10px;
        /* background-color: #D4E6FF; */
      }
      
      .uploads {
        display: inline-block;
        width: 160px;
        height: 160px;
        /* border-radius: 5px; */
        background: url(../img/task/dianjipaizhao.png) no-repeat;
        background-size: 100%;
        margin-bottom: 20px;
      }
      
      .submits {
        width: 100%;
        margin-top: 30px;
        height: 4 0px;
        border-radius: 30px;
      }
      /*.fixed-btn .mui-btn{
       width: 30%;
     }*/
      
      .putList {
        display: flex;
        justify-content: space-between;
        padding-bottom: 20px;
      }
      
      .putList input {
        width: 80%;
      }
      
      .mui-grid-view.mui-grid-9 {
        background-color: initial;
        border: none;
      }
      
      .image-warp {
        width: 100%;
        padding-bottom: 100%;
        position: relative;
      }
      
      .image-warp img {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
      }
      
      .image-del {
        width: 20px !important;
        font-size: 1.5rem;
        position: absolute;
        top: 0px;
        right: 0px;
      }
      
      .mui-grid-9-item {
        padding: 10px;
      }
      
      .mui-grid-view {
        display: flex;
        flex-wrap: wrap;
      }
      
      .areas {
        background-color: #F1F3F7;
      }
      
      .tips {
        text-align: center;
        font-weight: bold;
        line-height: 40px;
        font-size: 18px;
        border-bottom: 1px solid #DCDCDC;
      }
      
      .option {
        display: flex;
        justify-content: space-around;
        margin-top: 20px;
      }
      
      .option button {
        width: 80px;
      }
      
      .tips-list {
        margin-top: 40%;
      }
      
      .mui-navigate-right:after {
        right: 0;
      }
      
      .screens {
        position: absolute;
        top: 44px;
        left: 0;
        width: 100%;
        min-height: 200px;
        background-color: #fff;
        z-index: 999;
        border-radius: 0;
      }
      
      .square-item {
        width: 30px;
        height: 30px;
        border-radius: 3px;
        display: flex;
        justify-content: center;
        align-items: center;
        margin-top: 10px;
        margin-right: 15px;
       background: #F5F6F7;
        color: #333;
      }
      .square-item.bg-blue{
        color: #FFFFFF;
        background: #3188FE;
      }
      
      .square-item.active {
        border: 1px dashed #004AAF;
      }
      
      .square-item img {
        width: 15px;
        height: 15px;
      }
      
      .checkradios{
        margin-left: -15px;
      }
      .radios .rs1 {
        left: 100px;
      }

      .radios .rs2 {
        left: 180px;
      }

      .oks {
        position: absolute;
        left: 130px;
        top: 10px;
      }

      .nos {
        position: absolute;
        left: 210px;
        top: 10px;
      }
      
      .action-delete {
        position: absolute;
        left: 0;
        right: 0;
        bottom: 10px;
        background-color: rgba(0, 0, 0, 0.5);
        text-align: center;
        margin: 0 10px;
      }

      .action-delete .mui-icon {
        color: #FFFFFF;
      }
      
      .tips {
        text-align: center;
        font-weight: bold;
        line-height: 40px;
        font-size: 18px;
        border-bottom: 1px solid #DCDCDC;
      }
      
      .tips-list {
        margin-top: 30%;
      }
    </style>
  </head>

  <body>
    <div id="container" v-cloak>
      <header class="mui-bar mui-bar-nav">
        <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left text-white"></a>
        <h1 class="mui-title">工序执行</h1>
        <a class="mui-pull-right mui-bar-right" @click="screen">
          <img src="../img/screen.png" width="18" style="margin-right: 3px;" />
          <span> 筛选</span>
        </a>
      </header>
      <div class="mui-content page-wrap">
        <div class="mui-card-header" @tap="searchInfo()" style="padding: 20px;">
          <span>查询知识库</span>
        </div>
        <ul class="uls page-scroll" style="background: #FFFFFF;">
          <li class="lis" style="margin-bottom: 20px;">
            <div>
              {{pageIndex + 1}}、{{currentIndex + 1}}/{{allWp.length}} {{detail.position ? '辅助工序': '基本工序'}} 
            </div>
            <div>
              <span>工序编号：</span><span>{{detail.wpCode}}</span>
            </div>
            <div>
              <span>作业项目：</span><span>{{detail.jobProject}}</span>
            </div>
            <div>
              <span>作业方法：</span><span>{{detail.jobMethod}}</span>
            </div>
          </li>
          <li class="lis margin-bottom-sm" v-for="(item,index) in projectList" :key="index" v-cloak>
            <div class="titles">
              <span class="img_s">{{index+1}}</span>
              <span class="bocks">{{item.refInput.name}} {{item.refInput.explain}}：{{inputShowText(item.refInput, dict)}}</span>
            </div>
            <div v-show="!acceptIng">
              <div class="margin-bottom">
                <div>执行人填写：</div>
                <div v-if="item.refInput.typeValue == 'number'"> {{item.value}}&nbsp;{{item.refInput.unitValue}}</div>
                <div v-if="item.refInput.typeValue == 'text'"> {{item.remarks}}</div>
                <div v-if="item.refInput.typeValue == 'boolean'"> {{item.value}}</div>
                <ul class="mui-grid-view mui-grid-9" v-if="item.refInput.typeValue == 'img'">
                  <li class="mui-grid-9-item mui-col-xs-6 mui-col-sm-6 img-item" v-for="(item, i) in item.files">
                    <div class="image-warp">
                      <img :src="serverUrl + item.filePath" :data-preview-src="serverUrl + item.filePath" :data-preview-group="index + '' + 0" alt="" />
                    </div>
                  </li>
                </ul>
              </div>
              <div class="margin-bottom">
                <div>验收填写：</div>
                <div v-if="item.refInput.typeValue == 'number'"> {{item.checkValue}}&nbsp;{{item.refInput.unitValue}}</div>
                <div v-if="item.refInput.typeValue == 'text'"> {{item.checkRemarks}}</div>
                <div v-if="item.refInput.typeValue == 'boolean'"> {{item.checkValue}}</div>
                <ul class="mui-grid-view mui-grid-9" v-if="item.refInput.typeValue == 'img'">
                  <li class="mui-grid-9-item mui-col-xs-6 mui-col-sm-6 img-item" v-for="(item, i) in item.checkFiles">
                    <div class="image-warp">
                      <img :src="serverUrl + item.filePath" :data-preview-src="serverUrl + item.filePath" :data-preview-group="index + '' + 1" alt="" />
                    </div>
                  </li>
                </ul>
              </div>
            </div>

            <div v-show="acceptIng">
              <div v-if="item.refInput.typeValue == 'number'">
                <div class="putList">
                  <div>
                    <input v-model="item.checkValue" type="number" placeholder="请输入" class="val1" maxlength="20"/>{{item.refInput.unitValue}}
                  </div>
                </div>
              </div>
              <div v-if="item.refInput.typeValue == 'boolean'">
                <div class="mui-input-row mui-radio radios">
                  <label>选项(是否)：</label>
                  <input :name="'radio' + index + 1" v-model="item.checkValue" type="radio" value="是" class="rs1">
                  <span class="oks">是</span>
                  <input :name="'radio' + index + 1" v-model="item.checkValue"  type="radio" value="否" class="rs2">
                  <span class="nos">否</span>
                </div> 
              </div>
              <div v-if="item.refInput.typeValue == 'text'">
                <textarea v-model="item.checkRemarks" name="" class="areas" cols="30" rows="6" id="textarea" placeholder="请输入" maxlength="200"></textarea>
              </div>
              <ul class="mui-grid-view mui-grid-9"  v-if="item.refInput.typeValue == 'img'">
                <li class="mui-grid-9-item mui-col-xs-6 mui-col-sm-6 img-item" v-for="(item, i) in item.checkFiles">
                  <div class="image-warp">
                    <img :src="item.path || (serverUrl + item.filePath)" :data-preview-src="item.path || (serverUrl + item.filePath)" :data-preview-group="index + '' + 2" alt="" />
                  </div>
                  <!--<img src="../img/del.png" class="image-del" @tap="delImg('input', {index,i})"></img>-->
                  <div class="action-delete" @tap="delImg('input', {index,i})">
                    <span class="mui-icon mui-icon-trash"></span>
                  </div>
                </li>
                <li class="mui-grid-9-item mui-col-xs-6 mui-col-sm-6 img-item">
                  <div class="image-warp">
                    <img src="../img/task/dianjipaizhao.png" alt="" @tap="camera('input', index)" />
                  </div>
                </li>
              </ul>
            </div>
          </li>
          <li>
            <div class="checkradios" v-if="acceptIng">
              <div class="mui-input-row mui-radio radios">
                <label>是否正常：</label>
                <input name="radio1" v-model="detail.isAnomaly" type="radio" :value="false" class="rs1">
                <span class="oks">是</span>
                <input name="radio1" v-model="detail.isAnomaly"  type="radio" :value="true" class="rs2">
                <span class="nos">否</span>
              </div> 
            </div>
            <div class="checkradios" v-else>
              <div class="mui-input-row mui-radio radios">
                <label>是否正常：{{detail.isAnomaly? '否': '是'}}</label>
              </div> 
            </div>
			<!-- {{detail.isAnomaly}}---{{detail.anomalyInfo}} -->
            <div v-if="detail.isAnomaly">
            	<textarea v-if="acceptIng" v-model="detail.anomalyInfo.remarks" name="" class="areas" cols="30" rows="4" id="textarea" placeholder="请输入" maxlength="200"></textarea>
            	 <div v-else>
                {{detail.anomalyInfo.remarks}}
              </div>
            	 <ul class="mui-grid-view mui-grid-9">
                <li class="mui-grid-9-item mui-col-xs-6 mui-col-sm-6 img-item" v-for="(item, i) in detail.anomalyInfo.files">
                  <div class="image-warp">
                    <img :src="item.path || (serverUrl + item.filePath)" :data-preview-src="item.path || (serverUrl + item.filePath)" data-preview-group="anomalyInfo2" alt="" />
                  </div>
                  <div class="action-delete" @tap="delImg('anomalyInfo',{i})" v-if="acceptIng">
                    <span class="mui-icon mui-icon-trash"></span>
                  </div>
                </li> 
                <li class="mui-grid-9-item mui-col-xs-6 mui-col-sm-6 img-item" v-if="acceptIng">
                  <div class="image-warp">
                    <img src="../img/task/dianjipaizhao.png" alt="" @tap="camera('anomalyInfo')" />
                  </div>
                </li>
              </ul>
            </div>
          </li>
          
          <li>
            <div class="checkradios" v-if="acceptIng">
              <div class="mui-input-row mui-radio radios">
                <label>是否需整改：</label>
                <input name="radio2" v-model="detail.isRectify" type="radio" :checked="detail.isRectify=='是'?true:false" value="true" class="rs1">
                <span class="oks">是</span>
                <input name="radio2" v-model="detail.isRectify"  type="radio" :checked="detail.isRectify=='是'?true:false" value="false" class="rs2">
                <span class="nos">否</span>
              </div> 
            </div>
             <div class="checkradios" v-else-if="isAccept">
              <div class="mui-input-row mui-radio radios">
                <label>是否需整改：{{detail.isRectify? '是': '否'}}</label>
              </div> 
            </div>
          </li>
          <li>
            <div class="checkradios" v-if="acceptIng">
              <div class="mui-input-row mui-radio radios">
                <label>是否通过：</label>
                <input name="radio3" v-model="detail.isPass" type="radio" :value="true" class="rs1">
                <span class="oks">是</span>
                <input name="radio3" v-model="detail.isPass"  type="radio" :value="false" class="rs2">
                <span class="nos">否</span>
              </div> 
            </div>
            <div class="checkradios" v-else>
              <div class="mui-input-row mui-radio radios">
                <label>是否通过：{{detail.isPass? '是': '否'}}</label>
              </div> 
            </div>
			
            <!-- <ul class="mui-grid-view mui-grid-9">
              <li class="mui-grid-9-item mui-col-xs-6 mui-col-sm-6 img-item" v-for="(item, i) in passInfo.files">
                <div class="image-warp">
                  <img :src="item.path || (serverUrl + item.filePath)" :data-preview-src="item.path || (serverUrl + item.filePath)" data-preview-group="anomalyInfo2" alt="" />
                </div>
                <div class="action-delete" @tap="delImg('passInfo',{i})" v-if="acceptIng">
                  <span class="mui-icon mui-icon-trash"></span>
                </div>
              </li> 
              <li class="mui-grid-9-item mui-col-xs-6 mui-col-sm-6 img-item" v-if="acceptIng">
                <div class="image-warp">
                  <img src="../img/task/dianjipaizhao.png" alt="" @tap="camera('passInfo')" />
                </div>
              </li>
            </ul> -->
			
          </li>
          
        </ul>
        <div class="fixed-btn" v-if="acceptIng">
          <button type="button" @tap="saveInfo()" class="mui-btn mui-btn-primary margin-right-sm">保存</button>
          <button type="button" @tap="cancel()" class="mui-btn">取消</button>
        </div>
        <div class="fixed-btn" v-else>
          <button type="button" @tap="upInfo()" class="mui-btn margin-right-sm" v-if="pageIndex>0 || currentIndex> 0">上一个</button>
          <button type="button" @tap="acceptIng=true" class="mui-btn mui-btn-primary margin-right-sm" v-if="claimed == 1">执行验收</button>
          <button type="button" @tap="nextInfo()" class="mui-btn mui-btn-primary mui-btn-outlined" v-if="pageIndex<list.length-1 || currentIndex < allWp.length - 1">下一个</button>
        </div>

        <!--<div class="mui-backdrop" v-show="isShowMes">
          <div class="tips-list">

            <div class="mui-card card_content padding">
              <div class="tips">工作提醒</div>
              <div class="flex justify-between padding border-bottom" @tap="tipsDetail('reminders');read1=true">
                <span>工作提醒</span>
                <span v-if="read1" class="color-blue mui-navigate-right">已阅读</span>
                <span v-else class="color-999 mui-navigate-right">未阅读</span>

              </div>
              <div class="flex justify-between padding border-bottom" @tap="tipsDetail('instruction');read2=true">
                <span>操作须知</span>
                <span v-if="read2" class="color-blue mui-navigate-right">已阅读</span>
                <span v-else class="color-999 mui-navigate-right">未阅读</span>
              </div>
              <div class="option">
                <button type="button" class="mui-btn" @click="isShowMes=false">关闭</button>
              </div>
            </div>

          </div>
        </div>-->

        <div class="screens mui-popover mui-popover-top">
          <div class="mui-segmented-control mui-segmented-control-inverted mui-segmented-control-primary" style="background-color: #fff;border-bottom: 1px solid #DCDCDC;">
            <a class="mui-control-item mui-active" @tap="sliderIndex=0"><span class="txt">全部</span></a>
            <a class="mui-control-item" @tap="sliderIndex=1"><span class="txt">已验收</span></a>
            <a class="mui-control-item" @tap="sliderIndex=2"><span class="txt">未验收</span></a>
          </div>
          <div class="content_ul">
            <div class="flex flex-wrap padding border-bottom" style="padding-right: 0;margin-right: -15px;min-height: 96px;">
              <div :class="['square-item ', item.status == 4? 'bg-blue':'', item.index == pageIndex ? 'active' : '']" v-for="(item, i) in sliderList" :key="i" @tap="checkInfo(item)">
                <img src="../img/gongzuopiao_duigou.png" v-if="item.status == 4" />
                <span v-else>{{item.index + 1}}</span>
              </div>
            </div>
            <div class="padding flex justify-around">
              <!--<button type="button" class="mui-btn flex-sub margin-right" @tap="screen">取消</button>-->
              <button type="button" class="mui-btn flex-sub mui-btn-primary" @tap="getScreen">确定</button>
            </div>
          </div>
        </div>
      </div>
      
      <div class="mui-backdrop" v-show="isMask">
        <div class="tips-list">
          <div class="mui-card">
            <div class="tips">查询知识库</div>
            <div class="mui-card-content">
              <ul class="mui-table-view" v-if="dataList.length>0">
                <li class="mui-table-view-cell" v-for="(item,index) in dataList" :key="item.id" @tap="toDetails(item.id)">
                  <a class="mui-navigate-right">
                    <span>{{item.deviceModelName}}</span> -
                    <span>{{item.machineModel}}</span><br />
                    <span>{{item.title}}</span>
                  </a>
                </li>
              </ul>
              <div v-else>暂无数据</div>
            </div>
            <div class="mui-card-footer">
              <div></div>
              <button type="button" class="mui-btn" @click="isMask=false">关闭</button>
              <!--<button type="button" class="mui-btn mui-btn-primary">确定</button>-->
            </div>
          </div>
        </div>
      </div>
    </div>

    <script src="../../../js/mui.js"></script>
    <script src="../../../js/mui.pullToRefresh.js"></script>
    <script src="../../../js/mui.pullToRefresh.material.js"></script>
    <script src="../../../js/jquery-1.7.2.min.js"></script>
    <script src="../../../js/vue.js"></script>
    <!--<script src="../js/main.js"></script>-->
	<script src="../js/uploadImage.js"></script>
    <script src="../js/mkeyplus.base.js"></script>
    <script src="../../../js/mui.zoom.js"></script>
    <script src="../../../js/mui.previewimage.js" type="text/javascript" charset="utf-8"></script>
    <script src="../js/sqlite.js" type="text/javascript" charset="utf-8"></script>
    <script src="../js/indexDBs.js"></script>
    <script type="text/javascript">
      mui.init()
      mui.previewImage()
      var ids = 1; //当前页面数据id
      var dbId = 0
	  let materialsthis = null
      if(window.plus) {
        plusready();
      } else {
        document.addEventListener('plusready', plusready, false);
      }
      var self = null
      let dict = {}
      let lineType=null;
      let db={};
      const dbName = 'myDBcheck';
      const storeName = 'verifyList'; //仓库名
      let lineDetails= {};
     async function plusready() {
        self = plus.webview.currentWebview();
        ids = self.wpid
        dbId = self.dbId
        vm.pageIndex = self.i
        vm.list = self.list
        vm.claimed = self.claimed == null ? 1 : self.claimed
        lineType = getSysInfo();
        vm.lineType = getSysInfo();
        // 打开数据库 const dbName = 'myDBcheck', storeName = 'verifyList'
        await openDB(dbName, storeName, 1).then(res=>{
          console.log('openDB',res) 
          db=res;
        })
        mui.baseApp.getDict(['valueUnit', 'valueType', 'inputSymbol', 'wpTag']).then(res => {
          vm.dict = res
          dict = res
          vm.wpTagList = res.wpTag
        })
        if(!lineType){
          // 获取离线数据
          getLineData()
        } else {
		  getDataByKey(db, storeName,dbId).then(res=>{
		  	console.log('是否有离线数据',res)
		  	if(res == undefined){
				// getCacheData()
				getProject(ids)
		  		vm.isOnlineAndOfflineData = false
		  	} else {
				getLineData()
				vm.lineType = lineType = false
		  		vm.isOnlineAndOfflineData = true
		  	}
		  })
		}
      }
      let vm = new Vue({
        el: '#container',
        data: {
		  materialsthis: [],
		  isOnlineAndOfflineData: false,
          projectList: [],
          dict: dict,
          files: [],
          serverUrl: mui.baseApp.serverUrl,
          isShowMes: false,
          read1: false,
          read2: false,
          list: [],
          pageIndex: 0, // 当前所属所以
          sliderIndex: 0, //筛选分类索引
          acceptIng: false, ////是否正在验收
          detail: {
			// isPass: true
		  },
          // anomalyInfo: {
          //   files: []
          // },
          passInfo: {
            files: []
          },
          isAccept: false, // 是否验收过 保存显示验收信息
          allWp: [], //当前基本工序加辅助工序
          currentIndex: 0, //当前基本工序加辅助工序所在索引
          isMask: false,
          dataList: [],
          claimed: 0 ,// 任务领取状态 0 未被领取 1 自己领取 2 他人领取
          lxDatas:{},
          lineDetails:{},
          listDatas:{},
          lineType:null
        },
        computed: {
          sliderList() {
            return this.list.filter(item => {
              if(this.sliderIndex == 0) {
                return true
              } else if(this.sliderIndex == 1 && item.status == 4) { //以颜色
                return true
              } else if(this.sliderIndex == 2 && item.status != 4) { //未验收
                return true
              } else {
                return false
              }
            })
          }
        },
        created: function() {
          // getProject(ids)
        },
        methods: {
		// 添加图片
		addPics(index) {
		  var that = this;
		
		  page.imgUp(function(path) {
		    console.log('compress image path: ' + path)
		
		    plus.nativeUI.showWaiting('上传中')
		    if(!lineType){
		      if (that.projectList[index].files) {
		        that.projectList[index].files.push({
		          // fileId: res.data.id,
		          filePath: path,
		          path: path
		        })
		      } else {
		        that.projectList[index].files = [{
		          // fileId: res.data.id,
		          filePath: path,
		          path: path
		        }]
		      }
		      plus.nativeUI.closeWaiting()
		      return
		    }
		    mui.baseApp.upLoadFile(path, function(res) {
		      console.log(res)
		      plus.nativeUI.closeWaiting()
		      mui.toast("上传成功")
		      if (that.projectList[index].files) {
		        that.projectList[index].files.push({
		          fileId: res.data.id,
		          filePath: res.data.fileDirectory,
		          path: path
		        })
		      } else {
		        that.projectList[index].files = [{
		          fileId: res.data.id,
		          filePath: res.data.fileDirectory,
		          path: path
		        }]
		      }
		
		    })
		  });
		},
          saveInfo() {
            let then=this;
            console.log('编辑数据', this.projectList)
            let projectList = JSON.parse(JSON.stringify(this.projectList))
            let executeArrys = projectList.map(res => {
              return {
                value: res.value,
                files: res.files,
                remarks: res.remarks,
                basicWpInputId: res.basicWpInputId,
                id: res.checkId,
                basicWpType: res.basicWpType,
                refInput: res.refInput
              }
            })
            let checkArrys = projectList.map(res => {
              return {
                value: res.checkValue,
                files: res.checkFiles,
                remarks: res.checkRemarks,
                basicWpInputId: res.basicWpInputId,
                id: res.checkId,
                basicWpType: res.basicWpType,
                refInput: res.refInput
              }
            })
			
            console.log('验收值', checkArrys)
            
            let parm = {
              stage: 5,
              inputs: checkArrys,
              isAnomaly: this.detail.isAnomaly,
              isRectify: this.detail.isRectify,
              isPass: this.detail.isPass,
              isFault: false,
              anomalyInfo: this.detail.anomalyInfo,
              materials: this.materialsthis,
              // passInfo: this.passInfo
            }
            console.log('xin', parm.anomalyInfo)
            // return
            if(parm.isAnomaly) {
              if(!parm.anomalyInfo.remarks) {
                mui.toast('请输入异常信息')
                return false
              }
//            if(!parm.anomalyInfo.files.length) {
//              mui.toast('请上传异常附件')
//              return false
//            }
            }
            
            let ajaxName = 'wp'
            console.log("+++++++++++++")
            console.log(this.detail)
            if(this.detail.position) { //辅助工序
              parm.projectTaskSubWpId = vm.allWp[vm.currentIndex].projectTaskSubWpId
              ajaxName = 'subWp'
            } else {
              parm.projectTaskWpId = ids
            }
            console.log(parm)
            
            let checkParm = JSON.parse(JSON.stringify(parm))
            checkParm.checkInputs = checkParm.inputs
            delete checkParm.inputs
            Object.assign(vm.allWp[vm.currentIndex], checkParm)
            console.log(!lineType || vm.isOnlineAndOfflineData)
            if(!lineType || vm.isOnlineAndOfflineData){
				parm.inputs = executeArrys
				parm.checkInputs = checkArrys // 验收值
				console.log('缓存修改',parm)
				//return
        // 获取离线数据
        // getLineData()
        mui.confirm('当前是离线数据，是否需要保存编辑内容？','提示',['是','否'],function(item){
        console.log('对话框提示',item)
				plus.nativeUI.showWaiting('提交中...')
                if(item.index==0){
                  if(then.detail.position) {
                     if(lineDetails.subWps&&lineDetails.subWps.length>0){
                       lineDetails.subWps.forEach((item,i)=>{
                         if(item.projectTaskSubWpId==then.detail.projectTaskSubWpId){
                           lineDetails.subWps[i]=Object.assign(item,parm)
                           lineDetails.subWps[i].status=4
                           then.$set(lineDetails.subWps,i,Object.assign(item,parm))
                           // this.$set(lineDetails.details.subWps,i,Object.assign(item,parm))
                         }
                       })
                     }
                  }else{
                    lineDetails= Object.assign(lineDetails,parm)
                    lineDetails.status=4
                    then.listDatas.status=4
                  }
                  // console.log('okokokok',JSON.stringify(then.detail),JSON.stringify(then.lineDetails))
                  // lineDetails= Object.assign(lineDetails,parm)
                  // then.detail.status=4
 
                  console.log('编辑数据22000', then.lxDatas)
                  getUpdata(then.lxDatas,parm)
				  //resolve(parm)
                }else{
					plus.nativeUI.closeWaiting();
				}
              })
            }else{				
				// lineDetails= Object.assign(lineDetails,parm)
				
				plus.nativeUI.showWaiting('提交中...')
				// 删除提交参数path
				parm.inputs.forEach((a,i)=>{
					a.files === null ? [] :
					a.files.forEach((b,i)=>{
						delete a.files[i].path;  
					})
				})
				if(parm.signInfo !== undefined){
					delete parm.signInfo.takeImg.path
				}
				mui.baseApp.httpRequst("post", "/app/api/project/execution/" + ajaxName + "/execution", parm, (data) => {
				  console.log('数据列表', data)
				  plus.nativeUI.closeWaiting();
				  // then.detail.status=4
				  // then.lineDetails.status=4
				  // then.listDatas.status=4
				  // getUpdata(then.lxDatas)
				  mui.toast("保存成功")
				  //return
				  this.acceptIng = false
				  vm.allWp[vm.currentIndex].status = 4
				  if(!this.detail.position) {
					this.list[this.pageIndex].status = 4
				  }
				  
				  this.isAccept = true
				  let detailPage = plus.webview.getWebviewById('./detail.html')
				  let wpPage = plus.webview.getWebviewById('./workingList.html')
				  if(detailPage) {
					mui.fire(detailPage, 'back', {})
				  }
				  if(wpPage) {
					mui.fire(wpPage, 'back', {})
				  }
				  let noId = false
				  parm.inputs.forEach(item => {
					if(!item.id) {
					  noId = true
					}
				  })
				  if(noId) {
					if(!lineType){
					  getLineData('cancel')
					  return
					}
				  }
				  getProject(ids, 'cancel')
				}, function() {
				// mui.toast("保存失败")
				  plus.nativeUI.closeWaiting();
				  console.log("获取数据失败");
				})
			}

          },
          upInfo() {
            if(vm.currentIndex > 0) {
              vm.currentIndex--
              handleData({
                data: vm.allWp[vm.currentIndex]
              })
              return
            }
            this.pageIndex--
            ids = this.list[this.pageIndex].id
			      console.log(11, !lineType)
            if(!lineType){
              getLineData()
            }else{
              getProject(ids)
            }
            
          },
          nextInfo() {
            if(vm.currentIndex + 1 < vm.allWp.length) {
              vm.currentIndex++
              handleData({
                data: vm.allWp[vm.currentIndex]
              })
              return
            }
            this.pageIndex++
            ids = this.list[this.pageIndex].id
            console.log(11, !lineType)
            if(!lineType){
              getLineData()
            }else{
			  getProject(ids)
			}
            
          },
          checkInfo(item) {
            lineType = getSysInfo();
            vm.lineType = getSysInfo();
            if(this.pageIndex == item.index) {
              mui.toast('当前工序')
              return
            }
            this.pageIndex = item.index
            ids = item.id
            if(!lineType){
              getLineData()
              mui('.screens').popover('toggle');
              return
            }
            getProject(ids)
            mui('.screens').popover('toggle');
          },
          //取消验收
          cancel() {
            if(!lineType || this.isOnlineAndOfflineData){
              getLineData('cancel')
              this.acceptIng = false
            }else{
				getProject(ids, 'cancel')
				this.acceptIng = false
			}
            
          },
          inputShowText(obj, dict) {
            // console.log(obj)
            let type = dict.id.valueType[obj.typeId].value // 类型
            if(type == 'text') {
              return obj.value
            } else if(type == 'img') {
              return '无'
            } else if (type == 'boolean') {
              return '是否'
            } else {
              let unit = dict.id.valueUnit[obj.unitId].value // 单位
              let symbol = dict.id.inputSymbol[obj.typeSubId].value // 符号
              let valueArr = obj.value.split(",")
              let showText = ''
              switch(symbol) {
                case '>':
                  showText = '>' + valueArr[0] + unit
                  break;
                case '≥':
                  showText = '≥' + valueArr[0] + unit
                  break;
                case '<':
                  showText = '<' + valueArr[0] + unit
                  break;
                case '≤':
                  showText = '≤' + valueArr[0] + unit
                  break;
                case '=':
                  showText = '=' + valueArr[0] + unit
                  break;
                case '!=':
                  showText = '!=' + valueArr[0] + unit
                  break;
                case '()':
                  showText = '>' + valueArr[0] + unit + '  ' + '<' + valueArr[1] + unit
                  break;
                case '[]':
                  showText = '≥' + valueArr[0] + unit + '  ' + '≤' + valueArr[1] + unit
                  break;
                case '(]':
                  showText = '>' + valueArr[0] + unit + '  ' + '≤' + valueArr[1] + unit
                  break;
                case '[)':
                  showText = '≥' + valueArr[0] + unit + '  ' + '<' + valueArr[1] + unit
                  break;
                case ')(':
                  showText = '<' + valueArr[0] + unit + '  ' + '>' + valueArr[1] + unit
                  break;
                case '][':
                  showText = '≤' + valueArr[0] + unit + '  ' + '≥' + valueArr[1] + unit
                  break;
                case ')[':
                  showText = '<' + valueArr[0] + unit + '  ' + '≥' + valueArr[1] + unit
                  break;
                case '](':
                  showText = '≤' + valueArr[0] + unit + '  ' + '>' + valueArr[1] + unit
                  break;
                default:
                  showText = obj.value + unit
                  break
              }
              return showText
            }
          },
          delImg(type, obj) {
            let self = this
            let field = ''
            if(type == 'input') { //输入值
              field = self.projectList[obj.index].checkFiles
            } else if(type == 'anomalyInfo') { //异常
              field = self.detail.anomalyInfo.files
            } else if(type == 'passInfo') { //通过
              field = self.passInfo.files
            }
            mui.confirm("是否删除", "提示", ["取消", "确认"], function(e) {
              //            console.log(_src)
              if(e.index) {
                field.splice(obj.i, 1)
              }
            })
          },
          tipsDetail(type) {
            mui.baseApp.openWindow('../performTasks/carryoutTipsDetail.html?type=' + type)
          },
          camera(type, i) {
            console.log('aaaaaaaaaabbb',type)
            let self = this
            lineType = getSysInfo();
            this.lineType = getSysInfo();
            let field = []
            if(type == 'input') { //输入值
              field = this.projectList[i].checkFiles||[]
            } else if(type == 'anomalyInfo') { //异常
              field = this.detail.anomalyInfo.files||[]
			  console.log(44444,field)
            } else if(type == 'passInfo') { //通过
              field = this.passInfo.files||[]
            }
            console.log('aaaaaaaaaa',field)
            mui.baseApp.chooseImg().then(res => {
              mui.baseApp.compressImage(res).then(path => {
				
                console.log(path)
                plus.nativeUI.showWaiting('上传中')
                if(!lineType || vm.isOnlineAndOfflineData){
					plus.nativeUI.closeWaiting()
                  field.push({
                    // fileId: data.id,
                    filePath: path,
                    // filename: data.fileName,
                    path: path
                  })
				  if(type == 'anomalyInfo') { // 异常图片
				    self.detail.anomalyInfo.files = field
					console.log('------',self.detail)
				  }
				  console.log('上传离线图片',field)
				  
                } else {
					mui.baseApp.upLoadFile(path, function(res) {
					  console.log(res)
					  let data = res.data
					  plus.nativeUI.closeWaiting()
					  mui.toast("上传成功")
					  field.push({
					    fileId: data.id,
					    filePath: data.fileDirectory,
					    filename: data.fileName,
					    path: path
					  })
					  // self.$set(self.passInfo.files,field)
					  if(type == 'anomalyInfo') { // 异常图片
					    self.detail.anomalyInfo.files = field
					  }
					  console.log('上传在线图片',field)
					})
				}
              })
            })
          },
          screen() {
            mui('.screens').popover('toggle');
          },
          getScreen() {
            mui('.screens').popover('toggle');
          },
          searchInfo() {
            this.isMask = true
            // /app/api/project/execution/wpKnowledge/{projectTaskWpId}

          },
          getInfo() {
            let that = this;
            mui.baseApp.httpRequst("get", "/app/api/project/execution/wpKnowledge/" + ids, {}, function(data) {
              console.log('知识库', data)
              if (data.code == '0') {
                that.dataList = data.data
              } else {
                mui.toast(data.msg)
              }
            })
          },
          toDetails(id){
            mui.baseApp.openWindow("../knowledge/device/detail.html",{
              ids: id,
             })
          },
        },
      })
      function getProject(ids, type) {
        plus.nativeUI.showWaiting('加载中')
        mui.baseApp.httpRequst("get", "/app/api/project/execution/wp/detail/" + ids, {}, function(data) {
          console.log('数据列表', data)
          plus.nativeUI.closeWaiting();
          let subWps = data.data.subWps
          let prefix = []; // 前置
          let suffix = []; // 后置
          subWps.forEach(item => {
            item.isReturn = data.data.isReturn 
            if(item.position == 1) {
              prefix.push(item)
            } else {
              suffix.push(item)
            }
          })
          delete data.data.subWps
          vm.allWp = prefix.concat([data.data]).concat(suffix)

          if(type != 'cancel') { // 取消保持原来的
            vm.currentIndex = 0
          }
          
          handleData({
            data: vm.allWp[vm.currentIndex]
          })
        }, function() {
          // plus.nativeUI.closeWaiting()
          console.log("获取数据失败");
        })
        
        vm.getInfo()
      }
      function getCacheData(){
        getDataByKey(db, storeName,dbId).then(res=>{
          vm.lxDatas=res
          let data={}
          res.wpItemList.forEach(msg=>{
            if(msg.childs&&msg.childs.length>0){
              msg.childs.forEach(item=>{
                if(item.childs&&item.childs.length>0){
                  item.childs.forEach(v=>{
                     console.log('ok3',v)
                    if(v.childs&&v.childs.length>0){
                      console.log('ok4',v.childs)
                    }
                    if(v.taskWps&&v.taskWps.length>0){
                       v.taskWps.forEach(c=>{
                         if(c.id==ids){
                           console.log('ccc',c.details)
                           vm.listDatas=c
                           data=c.details
                         }
                       })
                    }
                  })
                }
                if(item.taskWps&&item.taskWps.length>0){
                   item.taskWps.forEach(b=>{
                     if(b.id==ids){
                       console.log('bbb',b.details)
                       vm.listDatas=b
                       data=b.details
                     }
                   })
                }
              })
            }
            if(msg.taskWps&&msg.taskWps.length>0){
               msg.taskWps.forEach(a=>{
                 if(a.id==ids){
                   console.log('aaa',a.details)
                   vm.listDatas=a
                   data=a.details
                 }
               })
            }
          })
          lineDetails=data
          vm.lineDetails=data
        })
      }
      function getLineData(type){
        console.log('离线id',ids,dbId)
        getDataByKey(db, storeName,dbId).then(res=>{
           plus.nativeUI.closeWaiting(); 
          console.log('获取离线数据',res.wpItemList)
          vm.lxDatas=res
          let data={}
          res.wpItemList.forEach(msg=>{
            if(msg.childs&&msg.childs.length>0){
              msg.childs.forEach(item=>{
                if(item.childs&&item.childs.length>0){
                  item.childs.forEach(v=>{
                     console.log('ok3',v)
                    if(v.childs&&v.childs.length>0){
                      console.log('ok4',v.childs)
                    }
                    if(v.taskWps&&v.taskWps.length>0){
                       v.taskWps.forEach(c=>{
                         if(c.id==ids){
                           console.log('ccc',c.details)
                           vm.listDatas=c
                           data=c.details
                         }
                       })
                    }
                  })
                }
                if(item.taskWps&&item.taskWps.length>0){
                   item.taskWps.forEach(b=>{
                     if(b.id==ids){
                       console.log('bbb',b.details)
                       vm.listDatas=b
                       data=b.details
                     }
                   })
                }
              })
            }
            if(msg.taskWps&&msg.taskWps.length>0){
               msg.taskWps.forEach(a=>{
                 if(a.id==ids){
                   console.log('aaa',a.details)
                   vm.listDatas=a
                   data=a.details
                 }
               })
            }
          })
          lineDetails=data
          vm.lineDetails=data
           console.log('离线数据获取123',data)
          let subWps = data.subWps||[]
            let prefix = []; // 前置
            let suffix = []; // 后置
            subWps.forEach(item => {
              item.isReturn = data.isReturn 
              if(item.position == 1) {
                prefix.push(item)
              } else {
                suffix.push(item)
              }
            })
            delete data.subWps
            vm.allWp = prefix.concat([data]).concat(suffix)
            if(type != 'cancel') { // 取消保持原来的
              vm.currentIndex = 0
            }
             console.log('离线数据获取333',vm.allWp,vm.currentIndex)
            handleData({
              data: vm.allWp[vm.currentIndex]
            })
          }, function() {
            // plus.nativeUI.closeWaiting()
            console.log("获取数据失败");
          })
          // console.log('离线数据获取',JSON.stringify(vm.allWp[vm.currentIndex]))
          // vm.getInfo()
      }
      function handleData(data) {
        console.log(222,data)
        data = JSON.parse(JSON.stringify(data))
        let checkInputs = data.data.checkInputs
        let inputs = data.data.inputs
        let lists = data.data.checkInputs.map((res, i) => {
          let id = res.refInput.id
          let type = res.refInput.basicWpType
          res['checkValue'] = checkInputs[i] ? (checkInputs[i].value || '') : ''
          res['checkRemarks'] = checkInputs[i] ? (checkInputs[i].remarks || ''): ''
          res['checkFiles'] = checkInputs[i] ?  (checkInputs[i].files || []): []
          res['checkId'] = checkInputs[i] ? (checkInputs[i].id || ''): ''
          // 先清空值
          res['value'] = ''
          res['remarks'] = ''
          res['files'] = []
          for(let i=0;i<inputs.length;i++) { //获取执行时填写的值
            let obj = inputs[i]
            if(id == obj.refInput.id && type == obj.refInput.basicWpType) {
              res['value'] = obj.value || ''
              res['remarks'] = obj.remarks || ''
              res['files'] = obj.files || []
              break;
            }
          }
          return res
        })
        console.log('新数据列表12', lists)
        vm.projectList = lists
        vm.detail = data.data
		// console.log('anomalyInfo',vm.detail.anomalyInfo)
		if(vm.detail.anomalyInfo == null) vm.detail.anomalyInfo = {files:[],remarks:''}
		vm.materialsthis = data.data.materials ? data.data.materials : []
        // if(data.data.anomalyInfo&&data.data.passInfo.files) {
        //   vm.anomalyInfo = data.data.anomalyInfo
        // } else {
        //   vm.anomalyInfo = {
        //     files: []
        //   }
        // }
        // if(data.data.passInfo&&data.data.passInfo.files) {
        //   vm.passInfo = data.data.passInfo
        // } else {
        //   vm.passInfo = {
        //     files: []
        //   }
        // }
        
        if(data.data.status == 0 ) { //未验收
          vm.isAccept =  false
          vm.detail.isPass = true
        } else {
          vm.isAccept =  true
        }
      }
      function getUpdata(lxDatas,parm){
         updateDB(db, storeName,lxDatas).then(msg=>{
           console.log('离线保存',JSON.stringify(msg))
           plus.nativeUI.closeWaiting();
           if(msg.isTrusted){
             mui.toast("保存成功")
              vm.acceptIng = false
              vm.allWp[vm.currentIndex].status = 4
              if(!vm.detail.position) {
                vm.list[vm.pageIndex].status = 4
              }
              mui.fire(self.opener(), 'plusready', {
                back: 1
              })
              vm.isAccept = true
              let detailPage = plus.webview.getWebviewById('./detail.html')
              let wpPage = plus.webview.getWebviewById('./workingList.html')
              if(detailPage) {
                mui.fire(detailPage, 'back', {})
              }
              if(wpPage) {
                mui.fire(wpPage, 'back', {})
              }
              let noId = false
              parm.inputs.forEach(item => {
                if(!item.id) {
                  noId = true
                }
              })
              if(noId) {
                if(!lineType){
                  getLineData('cancel')
                  return
                }
                getProject(ids, 'cancel')
              }
           }else{
             mui.toast("保存失败")
           }
              
         })
       }
      function getSysInfo() {
		  // return false
          types = {};
          types[plus.networkinfo.CONNECTION_UNKNOW] = "未知";
          types[plus.networkinfo.CONNECTION_NONE] = "未连接网络";
          types[plus.networkinfo.CONNECTION_ETHERNET] = "有线网络";
          types[plus.networkinfo.CONNECTION_WIFI] = "WiFi网络";
          types[plus.networkinfo.CONNECTION_CELL2G] = "2G蜂窝网络";
          types[plus.networkinfo.CONNECTION_CELL3G] = "3G蜂窝网络";
          types[plus.networkinfo.CONNECTION_CELL4G] = "4G蜂窝网络";
       
          var str = types[plus.networkinfo.getCurrentType()];
          if (str == '未知' || str == '未连接网络') {
              return false;
          } else {
              return true;
          }
       
      }
      $(document).ready(function() {
        let height = document.documentElement.clientHeight
        //防止软键盘弹出底部按钮顶上来
        $(".mui-content").css('height', height + 'px')
      })
	  
	  window.addEventListener('materialsthis', function(event) {
	    let data = event.detail
	    console.log('物料', data)
	    materialsthis = data.materialsthis
	    vm.materialsthis = data.materialsthis
	  });
    </script>
  </body>

</html>